<?php

use yii\db\Migration;

/**
 * Class m190912_055800_auth_rule
 */
class m190912_055800_auth_rule extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB COMMENT="权限规则表"';
        $this->createTable('{{%auth_rule}}', [
            'id' => $this->primaryKey(),
            'pid' => $this->integer()->notNull()->comment('父节点ID'),
            'module' => $this->string()->notNull()->defaultValue('admin')->comment('权限节点所属模块(后台默认admin)'),
            'level' => $this->integer()->notNull()->comment('1-项目;2-模块;3-操作'),
            'name' => $this->string(80)->notNull()->comment('权限路径'),
            'title' => $this->string(30)->notNull()->comment('权限路径名称'),
            'status' => $this->smallInteger()->notNull()->defaultValue(1)->comment('状态：为1正常，为0禁用 ，2为删除'),
            'ismenu' => $this->string()->notNull()->defaultValue(0)->comment('是否作为导航 0：否  1：是'),
            'sorts' => $this->integer()->defaultValue(50)->comment('权限排序'),
            'unique_key' => $this->string()->comment('唯一字段,前端使用'),
            'created_at' => $this->integer()->notNull(),
            'updated_at' => $this->integer()->notNull(),
            'deleted_at' => $this->integer(),
        ],$tableOptions);

    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        $this->dropTable('{{%auth_rule}}');

        return false;
    }

    /*
    // Use up()/down() to run migration code without a transaction.
    public function up()
    {

    }

    public function down()
    {
        echo "m190912_055800_auth_rule cannot be reverted.\n";

        return false;
    }
    */
}
